<template>
  <div class="dashboard-container">
    <div v-if="userType == 1" class="dashboard-text">尊敬的用户,您好！欢迎使用网上预习系统<br /><br />学号:{{ studentContent.sno }}<br />姓名:{{
      studentContent.name }}<br />所在班级:{{ studentContent.className }}</div>
    <div v-if="userType == 2" class="dashboard-text">
      尊敬的用户,您好！欢迎使用网上预习系统<br /><br />教师编号:{{ teacherContent.tno }}<br />姓名:{{ teacherContent.name
      }}<br />任课科目:{{ teacherContent.subjectName }}<br /><br /></div>
    <div v-if="userType == 2" class="dashboard-text">所教班级:<div v-for="item in teacherContent.classes"
        class="dashboard-text">{{ item.name }}</div>
    </div>
    <div v-if="userType == 0" class="dashboard-text">尊敬的管理员：{{ name }}，您好！欢迎使用网上预习系统</div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { getUserApi } from '@/api/user'

export default {
  name: 'home',
  data() {
    return {
      name: '',
      studentContent: {
        sno: 0,
        name: "",
        className: ""
      },
      teacherContent: {},
      userType: "",
    }
  },
  computed: {
    ...mapGetters([
      'name'
    ])
  },
  created() {
    this.userType = localStorage.getItem("type");
    if (this.userType == 1) {
      getUserApi().then((res) => {
        this.studentContent = res.data
      })
    } else if (this.userType == 2) {
      getUserApi().then((res) => {
        this.teacherContent = res.data
      })
    } else {
      getUserApi().then((res) => {
        this.name = res.data
      })
    }
  }
}


</script>

<style lang="scss" scoped>
.dashboard {
  &-container {
    margin: 30px;
  }

  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}
</style>
